//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.lijinjiang.beautyeye.ch5_table;

import com.lijinjiang.beautyeye.BeautyEyeLNFHelper;

import java.awt.Color;
import java.awt.Component;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
import java.io.Serializable;
import java.util.List;
import javax.swing.Icon;
import javax.swing.JTable;
import javax.swing.SortOrder;
import javax.swing.SwingUtilities;
import javax.swing.RowSorter.SortKey;
import javax.swing.border.Border;
import javax.swing.plaf.ColorUIResource;
import javax.swing.plaf.UIResource;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.JTableHeader;

public class DefaultTableCellHeaderRenderer extends DefaultTableCellRenderer implements UIResource {
    private boolean horizontalTextPositionSet;
    private Icon sortArrow;
    private EmptyIcon emptyIcon = new EmptyIcon();

    public DefaultTableCellHeaderRenderer() {
        this.setHorizontalAlignment(0);
    }

    public void setHorizontalTextPosition(int var1) {
        this.horizontalTextPositionSet = true;
        super.setHorizontalTextPosition(var1);
    }

    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        Icon icon = null;
        boolean var8 = false;
        if (table != null) {
            JTableHeader tableHeader = table.getTableHeader();
            if (tableHeader != null) {
                Color focusForeground = null;
                Color focusBackground = null;
                if (hasFocus) {
                    focusBackground = new ColorUIResource(BeautyEyeLNFHelper.focusCellBackground);
                    focusForeground = new ColorUIResource(BeautyEyeLNFHelper.focusCellBackground);
                    //var10 = DefaultLookup.getColor(this, this.ui, "TableHeader.focusCellForeground");
                    //var11 = DefaultLookup.getColor(this, this.ui, "TableHeader.focusCellBackground");
                }

                if (focusForeground == null) {
                    focusForeground = tableHeader.getForeground();
                }

                if (focusBackground == null) {
                    focusBackground = tableHeader.getBackground();
                }

                this.setForeground(focusForeground);
                this.setBackground(focusBackground);
                this.setFont(tableHeader.getFont());
                var8 = tableHeader.isPaintingForPrint();
            }

            if (!var8 && table.getRowSorter() != null) {
                if (!this.horizontalTextPositionSet) {
                    this.setHorizontalTextPosition(10);
                }

                SortOrder sortOrder = getColumnSortOrder(table, column);
                if (sortOrder != null) {
                    switch (sortOrder) {
                        case ASCENDING:
                            //var7 = DefaultLookup.getIcon(this, this.ui, "Table.ascendingSortIcon");
                            break;
                        case DESCENDING:
                            //var7 = DefaultLookup.getIcon(this, this.ui, "Table.descendingSortIcon");
                            break;
                        case UNSORTED:
                            //var7 = DefaultLookup.getIcon(this, this.ui, "Table.naturalSortIcon");
                    }
                }
            }
        }

        this.setText(value == null ? "" : value.toString());
        this.setIcon(icon);
        this.sortArrow = icon;
        Border border = null;
        if (hasFocus) {
            //border = DefaultLookup.getBorder(this, this.ui, "TableHeader.focusCellBorder");
        }

        if (border == null) {
            //var13 = DefaultLookup.getBorder(this, this.ui, "TableHeader.cellBorder");
        }

        this.setBorder(border);
        return this;
    }

    public static SortOrder getColumnSortOrder(JTable table, int i) {
        SortOrder var2 = null;
        if (table != null && table.getRowSorter() != null) {
            List var3 = table.getRowSorter().getSortKeys();
            if (var3.size() > 0 && ((SortKey) var3.get(0)).getColumn() == table.convertColumnIndexToModel(i)) {
                var2 = ((SortKey) var3.get(0)).getSortOrder();
            }

            return var2;
        } else {
            return var2;
        }
    }

    public void paintComponent(Graphics g) {
        boolean var2 = false;
        //boolean var2 = DefaultLookup.getBoolean(this, this.ui, "TableHeader.rightAlignSortArrow", false);
        if (var2 && this.sortArrow != null) {
            this.emptyIcon.width = this.sortArrow.getIconWidth();
            this.emptyIcon.height = this.sortArrow.getIconHeight();
            this.setIcon(this.emptyIcon);
            super.paintComponent(g);
            Point var3 = this.computeIconPosition(g);
            this.sortArrow.paintIcon(this, g, var3.x, var3.y);
        } else {
            super.paintComponent(g);
        }

    }

    private Point computeIconPosition(Graphics g) {
        FontMetrics var2 = g.getFontMetrics();
        Rectangle var3 = new Rectangle();
        Rectangle var4 = new Rectangle();
        Rectangle var5 = new Rectangle();
        Insets var6 = this.getInsets();
        var3.x = var6.left;
        var3.y = var6.top;
        var3.width = this.getWidth() - (var6.left + var6.right);
        var3.height = this.getHeight() - (var6.top + var6.bottom);
        SwingUtilities.layoutCompoundLabel(this, var2, this.getText(), this.sortArrow, this.getVerticalAlignment(), this.getHorizontalAlignment(), this.getVerticalTextPosition(), this.getHorizontalTextPosition(), var3, var5, var4, this.getIconTextGap());
        int var7 = this.getWidth() - var6.right - this.sortArrow.getIconWidth();
        int var8 = var5.y;
        return new Point(var7, var8);
    }

    private class EmptyIcon implements Icon, Serializable {
        int width;
        int height;

        private EmptyIcon() {
            this.width = 0;
            this.height = 0;
        }

        public void paintIcon(Component component, Graphics g, int x, int y) {
        }

        public int getIconWidth() {
            return this.width;
        }

        public int getIconHeight() {
            return this.height;
        }
    }
}
